"""
URL configuration for backend project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
# 从Django中导入必要的模块
from django.contrib import admin
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from django.conf import settings
from django.conf.urls.static import static

from book.views import BookViewSet, ArticleViewSet, CategoryViewSet
from account.views import CollectViewSet, OwnedViewSet
from ai.views import AIContinueAPIView, AIGrammarCheckAPIView


# 创建默认路由器对象
router = DefaultRouter()
# 注册 book 视图集到路由器中，并指定路径前缀为 'book'
router.register(r'book', BookViewSet, basename='book')
router.register(r'article', ArticleViewSet, basename='article')
router.register(r'category', CategoryViewSet, basename='category')
router.register(r'collect', CollectViewSet, basename='collect')
router.register(r'owned', OwnedViewSet, basename='owned')

# 定义 URL 路由列表
urlpatterns = [
    # 设置 admin 管理路径
    path('admin/', admin.site.urls),
    # 设置 API 路径，包括注册的视图集路由
    path('api/', include(router.urls)),
    # 用户相关API
    path('api/', include('djoser.urls')),
    path('api/', include('djoser.urls.jwt')),
    # AI续写接口
    path('api/ai-continue/', AIContinueAPIView.as_view()),
    path('api/ai-grammar-check/', AIGrammarCheckAPIView.as_view()),
]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
